﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region ProductOrderDao

        public List<tb_ProductOrder> GetAllProductOrder()
        {

            var query = (from obj in this.tb_ProductOrders
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_ProductOrder GetProductOrderById(int id)
        {
            return this.tb_ProductOrders.SingleOrDefault(tb_ProductOrder => tb_ProductOrder.Id == id);
        }

        public tb_ProductOrder GetProductOrderBySalesOrderId(int salesOrderId)
        {
            return this.tb_ProductOrders.SingleOrDefault(tb_ProductOrder => tb_ProductOrder.SalesOrderId == salesOrderId);
        }

        public void CreateProductOrder(tb_ProductOrder entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_ProductOrders.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyProductOrder(tb_ProductOrder entity)
        {
            tb_ProductOrder instance = this.tb_ProductOrders.SingleOrDefault(p => p.Id == entity.Id);
            instance.SalesOrderId = entity.SalesOrderId;
            instance.PumpingPrice = entity.PumpingPrice;
            instance.OutKMPrice = entity.OutKMPrice;
            instance.OtherPrice = entity.OtherPrice;
            instance.Id = entity.Id;
            instance.IsDelete = entity.IsDelete;
            instance.ConcretePrice = entity.ConcretePrice;
            instance.Status = entity.Status;
            instance.TotalPrice = entity.TotalPrice;

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }
        public void DeleteProductOrder(tb_ProductOrder entity)
        {
            tb_ProductOrder deleteEntity = tb_ProductOrders.SingleOrDefault(p => p.Id == entity.Id);
            tb_ProductOrders.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion
    }
}
